package com.trackerapp.database;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.trackerapp.model.DatabaseModel;


public class DatabaseHandler extends SQLiteOpenHelper {
	 
    // Database Version
    private static final int DATABASE_VERSION = 1;
 
    // Database Name
    private static final String DATABASE_NAME = "tracker.db";

    public DatabaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
 
    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("Create table " +  DatabaseModel.CELL_ID_TABLE +
        		"("+DatabaseModel.CELLID.CELLID_ID+" INTEGER PRIMARY KEY AUTOINCREMENT,"+
        		DatabaseModel.CELLID.PREV_CELL_ID + " INTEGER," +
        		DatabaseModel.CELLID.CURRENT_CELL_ID + " INTEGER," +
        		DatabaseModel.CELLID.LATITUDE + " INTEGER," +
        		DatabaseModel.CELLID.LONGITUDE + " INTEGER," +
        		DatabaseModel.CELLID.ACCURACY + " INTEGER" +");" );
        db.execSQL("Create table " +  DatabaseModel.PUSH_NOTIFICATION_TABLE +
        		"("+DatabaseModel.PUSH_NOTIFICATION.PUSH_ID+" INTEGER PRIMARY KEY AUTOINCREMENT,"+
        		DatabaseModel.PUSH_NOTIFICATION.MESSAGE + " TEXT NOT NULL," +
        		DatabaseModel.PUSH_NOTIFICATION.SENDER + " TEXT NOT NULL," +
        		DatabaseModel.PUSH_NOTIFICATION.CREATED_AT + " INTEGER," +
        		DatabaseModel.PUSH_NOTIFICATION.PUSH_MESSAGE_ID + " TEXT NOT NULL" +");" );        
    }    
    
 
    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed
    	// db.execSQL("DROP TABLE IF EXISTS " + DatabaseModel.SCORE_TABLE);
        // Create tables again
        onCreate(db);
    }
}

